package com.burgess.app;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class TextHelper {


    public static void createFile(final String strFilename, final String strBuffer) {
        try {
            // 创建文件对象
            File fileText = new File(strFilename);
            // 向文件写入对象写入信息
            FileWriter fileWriter = new FileWriter(fileText);

            // 写文件
            fileWriter.write(strBuffer);
            // 关闭
            fileWriter.close();
        } catch (IOException e) {
            //
            e.printStackTrace();
        }
    }

    public static boolean createDir(String destDirName) {
        File dir = new File(destDirName);
        if (dir.exists()) {
            System.out.println("创建目录" + destDirName + "失败，目标目录已经存在");
            return false;
        }
        if (!destDirName.endsWith(File.separator)) {
            destDirName = destDirName + File.separator;
        }
        //创建目录
        if (dir.mkdirs()) {
            System.out.println("创建目录" + destDirName + "成功！");
            return true;
        } else {
            System.out.println("创建目录" + destDirName + "失败！");
            return false;
        }
    }


    public static List<String> readTextTemplate(String filePath) {
        File text = new File(filePath);  // CSV文件路径
        InputStreamReader isr = null;
        BufferedReader br = null;
        List<String> allString = null;
        try {
            isr = new InputStreamReader(new FileInputStream(text), "GB18030");
            br = new BufferedReader(isr);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String line = "";
        String everyLine = "";
        try {
            allString = new ArrayList<>();
            while ((line = br.readLine()) != null)  //读取到的内容给line变量
            {
                everyLine = line;
                System.out.println(everyLine);
                allString.add(everyLine);
            }
            System.out.println("txt所有行数：" + allString.size());
            if (allString.size() > 1) {
                for (int i = 0; i < allString.size(); i++) {


                }
            }

        } catch (IOException e)

        {
            e.printStackTrace();
        }
        return allString;

    }

    public static void main(String[] args) {



    }

}
